package test.wk.constants;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import com.wk.job.Job;


public class DistributeJobServer1 {
	public static void main(String[] args) {
		try {
			@SuppressWarnings("resource")
			ServerSocket serverSocket = new ServerSocket(8080);
			while (true) {
				Socket socket = serverSocket.accept();
				ObjectInputStream objobin = new ObjectInputStream(socket.getInputStream());
				DataOutputStream out = new DataOutputStream(socket.getOutputStream()); 
				String message = "SUCESS";
				try {
					Job job = (Job)objobin.readObject();
					
					if(job != null){
						System.out.println(job.toString());
						message = "SUCESS";
					}else{
						message = "FAILD";
						System.out.println(message);
					}
					out.writeUTF(message);
					out.flush();
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				}
				objobin.close();
				out.close();
				socket.close();
			}
			
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
